package com.ruoyi.listener.improve;

import com.ruoyi.quality.domain.bo.QualityContinuousImprovementBo;
import com.ruoyi.quality.domain.vo.QualityContinuousImprovementVo;
import com.ruoyi.quality.service.IQualityContinuousImprovementService;
import org.flowable.engine.ProcessEngine;
import org.flowable.engine.ProcessEngines;
import org.flowable.engine.TaskService;
import org.flowable.engine.delegate.TaskListener;
import org.flowable.task.service.delegate.DelegateTask;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.Map;

@Component
public class GroupListener implements TaskListener {
    @Resource
    public IQualityContinuousImprovementService improvementService;

    private static GroupListener groupListener;

    @PostConstruct
    public void init() {
        groupListener = this;
        groupListener.improvementService = this.improvementService;
    }
    @Override
    public void notify(DelegateTask delegateTask) {
        //TODO 实现你的任务监听器逻辑
        System.out.println("执行任务监听器...");
        String assignee = delegateTask.getAssignee();

        String processInstanceId = delegateTask.getProcessInstanceId();

        QualityContinuousImprovementVo vo = groupListener.improvementService.queryByProcessInstanceId(processInstanceId);
        QualityContinuousImprovementBo bo = new QualityContinuousImprovementBo();
        BeanUtils.copyProperties(vo,bo);
        Long groupId = Long.valueOf(assignee);
        bo.setGroupId(groupId);
        groupListener.improvementService.updateByBo(bo);

    }
}
